package com.sdutcm.Controller;

import com.sdutcm.Domain.Student;
import com.sdutcm.Service.ServiceImpl.StudentServiceImpl;
import com.sdutcm.Service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/*
 *@Author Yan
 *@Create 2019-08-24 0:04
 */
@Controller
public class StudentController {


    @Autowired
    private StudentServiceImpl studentService;

    //添加
    @PostMapping("/studentadd")
    public String studentadd(Student student) throws Exception {
        studentService.studentadd(student);
        return "redirect:/studentlist";
    }


    //录入 无跳转

//    查看所有成员
    @GetMapping("/studentlist")
    public ModelAndView studentlist() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.addObject("studentlists",studentService.studentlist());
        mv.setViewName("student-list");
        return mv;
    }

//    查看历史所有成员
@GetMapping("/studentlist_his")
public ModelAndView studentlist_his() throws Exception {
    ModelAndView mv = new ModelAndView();
    mv.addObject("studentlists",studentService.studentlist_his());
    mv.setViewName("lend-list-his");
    return mv;
}



//    修改
    @GetMapping("/studentfindbyid/{id}")
    public ModelAndView studentfindbyid(@PathVariable("id") Integer s_id) throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.addObject("student",studentService.studentById(s_id));
        System.out.println(studentService.studentById(s_id));
        mv.setViewName("student-edit");
        return mv;
    }
    @PutMapping("/studentedit")
    public String studentedit(Student student) throws Exception {
        System.out.println(student);
        studentService.studentedit(student);
        return "redirect:/studentlist";
    }
}
